package cn.com.hori.cms.dao;

import cn.com.hori.cms.entities.ContentPublish;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 刘艺
 * @date 2018/3/12 10:41
 */
@Repository
public interface ContentRepository extends JpaRepository<ContentPublish, Long> {

    /**
     * 查询所有的文章
     *
     * @param columnId 文章所属栏目ID
     * @param pageable 分页参数
     * @return
     */
    @Query("select contentPublish from ContentPublish contentPublish where contentPublish.columnId=?1")
//    List<ContentPublish> findAllByColumnId(String columnId, Pageable pageable);
    List<ContentPublish> findAllByColumnId(String columnId);

    /**
     * 根据 contentId 查询一个文章的详细信息
     *
     * @param contentId 文章实体的 ID 非主键 唯一ID
     * @return 返回文章实体
     */
    @Query("select contentPublish from ContentPublish contentPublish where contentPublish.contentId=?1")
    ContentPublish findByContentId(String contentId);
}
